package com.xinyirun.scm.core.system.mapper.business.inventory;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinyirun.scm.bean.entity.business.wms.inventory.BDailyInventoryEntity;
import com.xinyirun.scm.bean.system.vo.business.wms.inventory.BDailyInventorySumVo;
import com.xinyirun.scm.bean.system.vo.business.wms.inventory.BDailyInventoryVo;
import com.xinyirun.scm.bean.system.vo.excel.query.MDailyInventoryExportVo;
import com.xinyirun.scm.common.constant.DictConstant;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 每日库存表 Mapper 接口
 * </p>
 *
 * @author wwl
 * @since 2022-01-23
 */
@Repository
public interface BDailyInventoryMapper extends BaseMapper<BDailyInventoryEntity> {

    String common_select = "  "
            + "			SELECT                                                                                                                                           "
            + "             ROW_NUMBER() over(order by t1.u_time desc) AS no,                                                                                            "
            + "				t1.id,												                                                                                         "
            + "				t1.dt,												                                                                                         "
            + "			    t2.code owner_code,                                                                                                                          "
            + "				t2.name owner_name,                                                                                                                          "
            + "				t2.short_name owner_short_name,                                                                                                              "
            + "				t7.name business_type_name,                                                                                                                  "
            + "				t7.code business_type_code,                                                                                                                  "
            + "				t6.name industry_name,                                                                                                                       "
            + "				t6.code industry_code,                                                                                                                       "
            + "				t5.name category_name,                                                                                                                       "
            + "				t5.code category_code,                                                                                                                       "
            + "				t4.name goods_name,                                                                                                                          "
            + "				t3.code sku_code,                                                                                                                            "
            + "				t3.spec sku_name,                                                                                                                            "
            + "				t4.code goods_code,                                                                                                                          "
            + "				t10.id prop_id,										                                                                                         "
            + "				t10.code prop_code,									                                                                                         "
            + "				t10.name goods_prop,									                                                                                         "
            + "				t3.pm,                                                                                                                                       "
            + "				t3.code spec_code,                                                                                                                           "
            + "				t3.name spec_name,                                                                                                                           "
            + "				t8.code warehouse_code,                                                                                                                      "
            + "				t8.name warehouse_name,                                                                                                                      "
            + "				t12.name location_name,                                                                                                                      "
            + "				t13.name bin_name,                                                                                                                           "
            + "				t9.code unit_code,                                                                                                                           "
            + "				'吨' unit_name,                                                                                                                              "
            + "				t1.qty,                                    			                                                                                         "
            + "				t1.qty_in,                                   		                                                                                         "
            + "				t1.qty_out,                               			                                                                                         "
            + "				t1.qty_adjust,                                                                                                                               "
            + "				ifnull(t1.qty_in,0)-ifnull(t1.qty_out,0)+ifnull(t1.qty_adjust,0) qty_diff,                                                                   "
            + "				t1.u_time,                      		                                                                                                     "
            + "				t1.u_time,                      		                                                                                                     "
            + "				t16.label warehouse_type_name,                      		                                                                                 "
            + "             CASE WHEN t14.sku_id is not null THEN t1.qty*t1.price                                                                                        "
            + "                 ELSE t1.qty*t11.price END AS realtime_amount,                                                                                            "
            + "             CASE WHEN t14.sku_id is not null THEN t1.price ELSE t11.price END AS realtime_price                                                          "
            + "			FROM                                                                                                                                             "
            + "				b_daily_inventory t1                                                                                                                         "
            + "				LEFT JOIN m_owner t2 on t1.owner_id = t2.id                                                                                                  "
            + "				LEFT JOIN m_goods_spec t3 on t1.sku_id = t3.id                                                                                               "
            + "				LEFT JOIN m_goods t4 on t3.goods_id = t4.id                                                                                                  "
            + "				LEFT JOIN m_category t5 on t4.category_id = t5.id                                                                                            "
            + "				LEFT JOIN m_industry t6 on t5.industry_id = t6.id                                                                                            "
            + "				LEFT JOIN m_business_type t7 on t6.business_id = t7.id                                                                                       "
            + "				LEFT JOIN m_warehouse t8 on t1.warehouse_id = t8.id                                                                                          "
            + "				LEFT JOIN m_unit t9 on t1.unit_id = t9.id                                                                                                    "
            + "				LEFT JOIN m_goods_spec_prop t10 on t3.prop_id = t10.id                                                                                       "
            + "				LEFT JOIN m_location t12 on t1.location_id = t12.id                                                                                          "
            + "				LEFT JOIN m_bin t13 on t1.bin_id = t13.id                                                                                                    "
            + "       left join(  SELECT                                                                                                                                 "
            + "         	sku_id,                                                                                                                                      "
            + "         	price,                                                                                                                                       "
            + "         	price_dt,                                                                                                                                    "
            + "         	c_time,                                                                                                                                      "
            + "         	row_number ( ) over ( PARTITION BY sku_id ORDER BY price_dt DESC, c_time DESC ) AS row_num                                                   "
            + "         FROM                                                                                                                                             "
            + "         	b_goods_price                                                                                                                                "
            + "            )t11 on t11.sku_id = t1.sku_id and t11.row_num = 1                                                                                            "
            + "	       LEFT JOIN(     SELECT                                                                                                                             "
            + "	            	t2.target_sku_id sku_id                                                                                                                  "
            + "	            FROM                                                                                                                                         "
            + "	            	b_material_convert t1                                                                                                                    "
            + "	            	INNER JOIN b_material_convert_detail t2 ON t2.material_convert_id = t1.id                                                                "
            + "	            WHERE                                                                                                                                        "
            + "	            	t1.is_effective = TRUE                                                                                                                   "
            + "	            	AND t2.is_effective = TRUE                                                                                                               "
            + "	            GROUP BY                                                                                                                                     "
            + "	            	t2.target_sku_id)t14 on t14.sku_id = t1.sku_id                                                                                           "
            + "   	    LEFT JOIN v_dict_info t16 on t16.code = '" + DictConstant.DICT_M_WAREHOUSE_TYPE + "' and t16.dict_value = t8.warehouse_type                      "
            + " ,(select @row_num:=0) t15                                                                                                                                ";


    String common_select_new = "  "
            + "	SELECT                                                                                                                                   "
            + "		ROW_NUMBER () over ( ORDER BY tt1.u_time DESC ) AS NO,                                                                               "
            + "		tt1.*                                                                                                                                "
            + "	FROM                                                                                                                                     "
            + "		(                                                                                                                                    "
            + "		SELECT                                                                                                                               "
            + "			concat('-', tab7.id, tab5.id, tab6.id) AS id,                                                                                    "
            + "			CURRENT_DATE dt,                                                                                                                 "
            + "			tab6.CODE owner_code,                                                                                                            "
            + "			tab6.NAME owner_name,                                                                                                            "
            + "			tab6.short_name owner_short_name,                                                                                                "
            + "			tab14.NAME business_type_name,                                                                                                   "
            + "			tab14.CODE business_type_code,                                                                                                   "
            + "			tab13.NAME industry_name,                                                                                                        "
            + "			tab13.CODE industry_code,                                                                                                        "
            + "			tab12.NAME category_name,                                                                                                        "
            + "			tab12.CODE category_code,                                                                                                        "
            + "			tab11.NAME goods_name,                                                                                                           "
            + "			tab7.CODE sku_code,                                                                                                              "
            + "			tab7.spec sku_name,                                                                                                              "
            + "			tab11.CODE goods_code,                                                                                                           "
            + "			tab15.id prop_id,                                                                                                                "
            + "			tab15.CODE prop_code,                                                                                                            "
            + "			tab15.NAME goods_prop,                                                                                                           "
            + "			tab7.pm pm,                                                                                                                      "
            + "			tab7.CODE spec_code,                                                                                                             "
            + "			tab7.NAME spec_name,                                                                                                             "
            + "			tab5.CODE warehouse_code,                                                                                                        "
            + "			tab5.NAME warehouse_name,                                                                                                        "
            + "			tab8.NAME location_name,                                                                                                         "
            + "			tab9.NAME bin_name,                                                                                                              "
            + "			tab9.id bin_id,                                                                                                                  "
            + "			tab16.CODE unit_code,                                                                                                            "
            + "			'吨' unit_name,                                                                                                                  "
            + "			ROUND(                                                                                                                           "
            + "				tab1.qty,                                                                                                                    "
            + "				4                                                                                                                            "
            + "			) AS qty,                                                                                                                        "
            + "			ROUND( IFNULL( tab18.qty_in, 0 ), 4 ) qty_in,                                                                                    "
            + "			ROUND( IFNULL( tab18.qty_out, 0 ), 4 ) qty_out,                                                                                  "
            + "			ROUND( IFNULL( tab18.qty_adjust, 0 ), 4 ) qty_adjust,                                                                            "
            + "			ROUND( IFNULL( tab18.qty_diff, 0 ), 4 ) qty_diff,                                                                                "
            + "			now() c_time,                                                                                                                    "
            + "			now() u_time,                                                                                                                    "
            + "			tab17.label warehouse_type_name,                                                                                                 "
            + "			0 realtime_amount,                                                                                                               "
            + "			0 realtime_price,                                                                                                                "
            + "         tab5.warehouse_type warehouse_type,                                                                                              "
            + "         tab5.id warehouse_id ,                                                                                                           "
            + "			tab6.id owner_id                                                                                                                 "
            + "		FROM                                                                                                                                 "
            + "			(                                                                                                                                "
            + "		SELECT                                                                                                                               "
            + "			warehouse_id,                                                                                                                    "
            + "			owner_id,                                                                                                                        "
            + "			sku_id,                                                                                                                          "
            + "			unit_id,                                                                                                                         "
            + "			sum( qty_in ) qty_in,                                                                                                            "
            + "			sum( qty_out ) qty_out,                                                                                                          "
            + "			sum( qty_adjust ) qty_adjust,                                                                                                    "
            + "			sum( qty_in ) - sum( qty_out ) + sum( qty_adjust ) AS qty                                                                        "
            + "		FROM                                                                                                                                 "
            + "			(                                                                                                                                "
            + "			SELECT                                                                                                                           "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id,                                                                                                                   "
            + "				t1.unit_id,                                                                                                                  "
            + "				sum( t1.actual_weight ) qty_in,                                                                                              "
            + "				0 qty_out,                                                                                                                   "
            + "				0 qty_adjust                                                                                                                 "
            + "			FROM                                                                                                                             "
            + "				b_in t1                                                                                                                      "
            + "			WHERE                                                                                                                            "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) &lt;= DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         "
            + "			GROUP BY                                                                                                                         "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id UNION ALL                                                                                                          "
            + "			SELECT                                                                                                                           "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id,                                                                                                                   "
            + "				t1.unit_id,                                                                                                                  "
            + "				0 qty_in,                                                                                                                    "
            + "				sum( t1.actual_weight ) qty_out,                                                                                             "
            + "				0 qty_adjust                                                                                                                 "
            + "			FROM                                                                                                                             "
            + "				b_out t1                                                                                                                     "
            + "			WHERE                                                                                                                            "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) &lt;= DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         "
            + "			GROUP BY                                                                                                                         "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id UNION ALL                                                                                                          "
            + "			SELECT                                                                                                                           "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t2.owner_id,                                                                                                                 "
            + "				t1.sku_id,                                                                                                                   "
            + "				NULL unit_id,                                                                                                                "
            + "				0 qty_in,                                                                                                                    "
            + "				0 qty_out,                                                                                                                   "
            + "				sum( t1.qty_diff ) qty_adjust                                                                                                "
            + "			FROM                                                                                                                             "
            + "				b_adjust_detail t1                                                                                                           "
            + "				LEFT JOIN b_adjust t2 ON t2.id = t1.adjust_id                                                                                "
            + "			WHERE                                                                                                                            "
            + "				t1.STATUS = '2'                                                                                                              "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) &lt;= DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         "
            + "			GROUP BY                                                                                                                         "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t2.owner_id,                                                                                                                 "
            + "				t1.sku_id                                                                                                                    "
            + "			) ttab                                                                                                                           "
            + "		GROUP BY                                                                                                                             "
            + "			warehouse_id,                                                                                                                    "
            + "			sku_id,                                                                                                                          "
            + "			owner_id                                                                                                                         "
            + "			) tab1                                                                                                                           "
            + "			LEFT JOIN m_warehouse tab5 ON tab1.warehouse_id = tab5.id                                                                        "
            + "			LEFT JOIN m_owner tab6 ON tab1.owner_id = tab6.id                                                                                "
            + "			LEFT JOIN m_goods_spec tab7 ON tab1.sku_id = tab7.id                                                                             "
            + "			LEFT JOIN m_location tab8 ON tab8.warehouse_id = tab5.id                                                                         "
            + "			LEFT JOIN m_bin tab9 ON tab9.location_id = tab8.id                                                                               "
            + "			LEFT JOIN m_inventory tab10 ON tab1.warehouse_id = tab10.warehouse_id                                                            "
            + "			AND tab1.owner_id = tab10.owner_id                                                                                               "
            + "			AND tab1.sku_id = tab10.sku_id                                                                                                   "
            + "			LEFT JOIN m_goods tab11 ON tab7.goods_id = tab11.id                                                                              "
            + "			LEFT JOIN m_category tab12 ON tab11.category_id = tab12.id                                                                       "
            + "			LEFT JOIN m_industry tab13 ON tab13.id = tab12.industry_id                                                                       "
            + "			LEFT JOIN m_business_type tab14 ON tab14.id = tab13.business_id                                                                  "
            + "			LEFT JOIN m_goods_spec_prop tab15 ON tab15.id = tab7.prop_id                                                                     "
            + "			LEFT JOIN m_unit tab16 ON tab1.unit_id = tab16.id                                                                                "
            + "			LEFT JOIN v_dict_info tab17 ON tab17.CODE = 'm_warehouse_type'                                                                   "
            + "			AND tab17.dict_value = tab5.warehouse_type                                                                                       "
            + "			LEFT JOIN (                                                                                                                      "
            + "		SELECT                                                                                                                               "
            + "			warehouse_id,                                                                                                                    "
            + "			owner_id,                                                                                                                        "
            + "			sku_id,                                                                                                                          "
            + "			unit_id,                                                                                                                         "
            + "			sum( qty_in ) qty_in,                                                                                                            "
            + "			sum( qty_out ) qty_out,                                                                                                          "
            + "			sum( qty_adjust ) qty_adjust,                                                                                                    "
            + "			sum( qty_in ) - sum( qty_out ) + sum( qty_adjust ) AS qty_diff                                                                   "
            + "		FROM                                                                                                                                 "
            + "			(                                                                                                                                "
            + "			SELECT                                                                                                                           "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id,                                                                                                                   "
            + "				t1.unit_id,                                                                                                                  "
            + "				sum( t1.actual_weight ) qty_in,                                                                                              "
            + "				0 qty_out,                                                                                                                   "
            + "				0 qty_adjust                                                                                                                 "
            + "			FROM                                                                                                                             "
            + "				b_in t1                                                                                                                      "
            + "			WHERE                                                                                                                            "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) = DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                             "
            + "			GROUP BY                                                                                                                         "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id UNION ALL                                                                                                          "
            + "			SELECT                                                                                                                           "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id,                                                                                                                   "
            + "				t1.unit_id,                                                                                                                  "
            + "				0 qty_in,                                                                                                                    "
            + "				sum( t1.actual_weight ) qty_out,                                                                                             "
            + "				0 qty_adjust                                                                                                                 "
            + "			FROM                                                                                                                             "
            + "				b_out t1                                                                                                                     "
            + "			WHERE                                                                                                                            "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) = DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                             "
            + "			GROUP BY                                                                                                                         "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t1.owner_id,                                                                                                                 "
            + "				t1.sku_id UNION ALL                                                                                                          "
            + "			SELECT                                                                                                                           "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t2.owner_id,                                                                                                                 "
            + "				t1.sku_id,                                                                                                                   "
            + "				NULL unit_id,                                                                                                                "
            + "				0 qty_in,                                                                                                                    "
            + "				0 qty_out,                                                                                                                   "
            + "				sum( t1.qty_diff ) qty_adjust                                                                                                "
            + "			FROM                                                                                                                             "
            + "				b_adjust_detail t1                                                                                                           "
            + "				LEFT JOIN b_adjust t2 ON t2.id = t1.adjust_id                                                                                "
            + "			WHERE                                                                                                                            "
            + "				t1.STATUS = '2'                                                                                                              "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) = DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                             "
            + "			GROUP BY                                                                                                                         "
            + "				t1.warehouse_id,                                                                                                             "
            + "				t2.owner_id,                                                                                                                 "
            + "				t1.sku_id                                                                                                                    "
            + "			) ttab                                                                                                                           "
            + "		GROUP BY                                                                                                                             "
            + "			warehouse_id,                                                                                                                    "
            + "			sku_id,                                                                                                                          "
            + "			owner_id                                                                                                                         "
            + "			) tab18 ON tab1.warehouse_id = tab18.warehouse_id                                                                                "
            + "			AND tab1.owner_id = tab18.owner_id                                                                                               "
            + "			AND tab1.sku_id = tab18.sku_id                                                                                                   "
            + "		HAVING                                                                                                                               "
            + "			qty != 0 UNION ALL                                                                                                               "
            + "		SELECT                                                                                                                               "
            + "			t1.id,                                                                                                                           "
            + "			t1.dt,                                                                                                                           "
            + "			t2.CODE owner_code,                                                                                                              "
            + "			t2.NAME owner_name,                                                                                                              "
            + "			t2.short_name owner_short_name,                                                                                                  "
            + "			t7.NAME business_type_name,                                                                                                      "
            + "			t7.CODE business_type_code,                                                                                                      "
            + "			t6.NAME industry_name,                                                                                                           "
            + "			t6.CODE industry_code,                                                                                                           "
            + "			t5.NAME category_name,                                                                                                           "
            + "			t5.CODE category_code,                                                                                                           "
            + "			t4.NAME goods_name,                                                                                                              "
            + "			t3.CODE sku_code,                                                                                                                "
            + "			t3.spec sku_name,                                                                                                                "
            + "			t4.CODE goods_code,                                                                                                              "
            + "			t10.id prop_id,                                                                                                                  "
            + "			t10.CODE prop_code,                                                                                                              "
            + "			t10.NAME goods_prop,                                                                                                             "
            + "			t3.pm,                                                                                                                           "
            + "			t3.CODE spec_code,                                                                                                               "
            + "			t3.NAME spec_name,                                                                                                               "
            + "			t8.CODE warehouse_code,                                                                                                          "
            + "			t8.NAME warehouse_name,                                                                                                          "
            + "			t12.NAME location_name,                                                                                                          "
            + "			t13.NAME bin_name,                                                                                                               "
            + "			t13.id bin_id,                                                                                                                   "
            + "			t9.CODE unit_code,                                                                                                               "
            + "			'吨' unit_name,                                                                                                                  "
            + "			t1.qty,                                                                                                                          "
            + "			t1.qty_in,                                                                                                                       "
            + "			t1.qty_out,                                                                                                                      "
            + "			t1.qty_adjust,                                                                                                                   "
            + "			ifnull( t1.qty_in, 0 )- ifnull( t1.qty_out, 0 )+ ifnull( t1.qty_adjust, 0 ) qty_diff,                                            "
            + "			t1.c_time,                                                                                                                       "
            + "			t1.u_time,                                                                                                                       "
            + "			t16.label warehouse_type_name,                                                                                                   "
            + "		CASE                                                                                                                                 "
            + "				                                                                                                                             "
            + "				WHEN t14.sku_id IS NOT NULL THEN                                                                                             "
            + "				t1.qty * t1.price ELSE t1.qty * t11.price                                                                                    "
            + "			END AS realtime_amount,                                                                                                          "
            + "		CASE                                                                                                                                 "
            + "				                                                                                                                             "
            + "				WHEN t14.sku_id IS NOT NULL THEN                                                                                             "
            + "				t1.price ELSE t11.price                                                                                                      "
            + "			END AS realtime_price,                                                                                                           "
            + "         t8.warehouse_type,                                                                                                               "
            + "			t8.id warehouse_id,                                                                                                              "
            + "			t2.id owner_id                                                                                                                   "
            + "		FROM                                                                                                                                 "
            + "			b_daily_inventory t1                                                                                                             "
            + "			LEFT JOIN m_owner t2 ON t1.owner_id = t2.id                                                                                      "
            + "			LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                                                                   "
            + "			LEFT JOIN m_goods t4 ON t3.goods_id = t4.id                                                                                      "
            + "			LEFT JOIN m_category t5 ON t4.category_id = t5.id                                                                                "
            + "			LEFT JOIN m_industry t6 ON t5.industry_id = t6.id                                                                                "
            + "			LEFT JOIN m_business_type t7 ON t6.business_id = t7.id                                                                           "
            + "			LEFT JOIN m_warehouse t8 ON t1.warehouse_id = t8.id                                                                              "
            + "			LEFT JOIN m_unit t9 ON t1.unit_id = t9.id                                                                                        "
            + "			LEFT JOIN m_goods_spec_prop t10 ON t3.prop_id = t10.id                                                                           "
            + "			LEFT JOIN m_location t12 ON t1.location_id = t12.id                                                                              "
            + "			LEFT JOIN m_bin t13 ON t1.bin_id = t13.id                                                                                        "
            + "			LEFT JOIN (                                                                                                                      "
            + "			SELECT                                                                                                                           "
            + "				sku_id,                                                                                                                      "
            + "				price,                                                                                                                       "
            + "				price_dt,                                                                                                                    "
            + "				c_time,                                                                                                                      "
            + "				row_number ( ) over ( PARTITION BY sku_id ORDER BY price_dt DESC, c_time DESC ) AS row_num                                   "
            + "			FROM                                                                                                                             "
            + "				b_goods_price                                                                                                                "
            + "			) t11 ON t11.sku_id = t1.sku_id                                                                                                  "
            + "			AND t11.row_num = 1                                                                                                              "
            + "			LEFT JOIN (                                                                                                                      "
            + "			SELECT                                                                                                                           "
            + "				t2.target_sku_id sku_id                                                                                                      "
            + "			FROM                                                                                                                             "
            + "				b_material_convert t1                                                                                                        "
            + "				INNER JOIN b_material_convert_detail t2 ON t2.material_convert_id = t1.id                                                    "
            + "			WHERE                                                                                                                            "
            + "				t1.is_effective = TRUE                                                                                                       "
            + "				AND t2.is_effective = TRUE                                                                                                   "
            + "			GROUP BY                                                                                                                         "
            + "				t2.target_sku_id                                                                                                             "
            + "			) t14 ON t14.sku_id = t1.sku_id                                                                                                  "
            + "			LEFT JOIN v_dict_info t16 ON t16.CODE = 'm_warehouse_type'                                                                       "
            + "			AND t16.dict_value = t8.warehouse_type                                                                                           "
            + "		) tt1                                                                                                                                ";


    String sum_select = "  "
            + "			SELECT                                                                                                                                           "
            + "				sum(t1.qty) qty,                                    			                                                                             "
            + "				sum(t1.qty_in) qty_in,                                   		                                                                             "
            + "				sum(t1.qty_out) qty_out,                               			                                                                             "
            + "				sum(t1.qty_adjust) qty_adjust,                                                                                                               "
            + "             sum(CASE WHEN t14.sku_id is not null THEN t1.qty*t1.price                                                                                    "
            + "                 ELSE t1.qty*t11.price END) AS realtime_amount                                                                                            "
            + "			FROM                                                                                                                                             "
            + "				b_daily_inventory t1                                                                                                                         "
            + "				LEFT JOIN m_owner t2 on t1.owner_id = t2.id                                                                                                  "
            + "				LEFT JOIN m_goods_spec t3 on t1.sku_id = t3.id                                                                                               "
            + "				LEFT JOIN m_goods t4 on t3.goods_id = t4.id                                                                                                  "
            + "				LEFT JOIN m_category t5 on t4.category_id = t5.id                                                                                            "
            + "				LEFT JOIN m_industry t6 on t5.industry_id = t6.id                                                                                            "
            + "				LEFT JOIN m_business_type t7 on t6.business_id = t7.id                                                                                       "
            + "				LEFT JOIN m_warehouse t8 on t1.warehouse_id = t8.id                                                                                          "
            + "				LEFT JOIN m_unit t9 on t1.unit_id = t9.id                                                                                                    "
            + "				LEFT JOIN m_goods_spec_prop t10 on t3.prop_id = t10.id                                                                                       "
            + "				LEFT JOIN m_location t12 on t1.location_id = t12.id                                                                                          "
            + "				LEFT JOIN m_bin t13 on t1.bin_id = t13.id                                                                                                    "
            + "       left join(  SELECT                                                                                                                                 "
            + "         	sku_id,                                                                                                                                      "
            + "         	price,                                                                                                                                       "
            + "         	price_dt,                                                                                                                                    "
            + "         	c_time,                                                                                                                                      "
            + "         	row_number ( ) over ( PARTITION BY sku_id ORDER BY price_dt DESC, c_time DESC ) AS row_num                                                   "
            + "         FROM                                                                                                                                             "
            + "         	b_goods_price                                                                                                                                "
            + "            )t11 on t11.sku_id = t1.sku_id and t11.row_num = 1                                                                                            "
            + "	       LEFT JOIN(     SELECT                                                                                                                             "
            + "	            	t2.target_sku_id sku_id                                                                                                                  "
            + "	            FROM                                                                                                                                         "
            + "	            	b_material_convert t1                                                                                                                    "
            + "	            	INNER JOIN b_material_convert_detail t2 ON t2.material_convert_id = t1.id                                                                "
            + "	            WHERE                                                                                                                                        "
            + "	            	t1.is_effective = TRUE                                                                                                                   "
            + "	            	AND t2.is_effective = TRUE                                                                                                               "
            + "	            GROUP BY                                                                                                                                     "
            + "	            	t2.target_sku_id)t14 on t14.sku_id = t1.sku_id                                                                                           "
            + " ,(select @row_num:=0) t15                                                                                                           ";


    String sum_select_new = "  "
            + "	SELECT                                                                                                                                                         "
            + "		sum( qty ) qty,                                                                                                                                            "
            + "		sum( qty_in ) qty_in,                                                                                                                                      "
            + "		sum( qty_out ) qty_out,                                                                                                                                    "
            + "		sum( qty_adjust ) qty_adjust,                                                                                                                              "
            + "		sum( CASE WHEN tt3.sku_id IS NOT NULL THEN tt1.realtime_amount ELSE tt1.qty * tt2.price END ) AS realtime_amount                                           "
            + "	FROM                                                                                                                                                           "
            + "		(                                                                                                                                                          "
            + "		SELECT                                                                                                                                                     "
            + "			tab1.sku_id,                                                                                                                                           "
            + "			0 AS id,                                                                                                                                               "
            + "			CURRENT_DATE dt,                                                                                                                                       "
            + "			tab6.CODE owner_code,                                                                                                                                  "
            + "			tab6.NAME owner_name,                                                                                                                                  "
            + "			tab6.short_name owner_short_name,                                                                                                                      "
            + "			tab14.NAME business_type_name,                                                                                                                         "
            + "			tab14.CODE business_type_code,                                                                                                                         "
            + "			tab13.NAME industry_name,                                                                                                                              "
            + "			tab13.CODE industry_code,                                                                                                                              "
            + "			tab12.NAME category_name,                                                                                                                              "
            + "			tab12.CODE category_code,                                                                                                                              "
            + "			tab11.NAME goods_name,                                                                                                                                 "
            + "			tab7.CODE sku_code,                                                                                                                                    "
            + "			tab7.NAME sku_name,                                                                                                                                    "
            + "			tab11.CODE goods_code,                                                                                                                                 "
            + "			tab15.id prop_id,                                                                                                                                      "
            + "			tab15.CODE prop_code,                                                                                                                                  "
            + "			tab15.NAME goods_prop,                                                                                                                                 "
            + "			tab7.pm pm,                                                                                                                                            "
            + "			tab7.CODE spec_code,                                                                                                                                   "
            + "			tab7.NAME spec_name,                                                                                                                                   "
            + "			tab5.CODE warehouse_code,                                                                                                                              "
            + "			tab5.NAME warehouse_name,                                                                                                                              "
            + "			tab8.NAME location_name,                                                                                                                               "
            + "			tab9.NAME bin_name,                                                                                                                                    "
            + "			tab9.id bin_id,                                                                                                                                        "
            + "			'吨' unit_name,                                                                                                                                        "
            + "			ROUND(                                                                                                                                                 "
            + "				tab1.qty,                                                                                                                                          "
            + "				4                                                                                                                                                  "
            + "			) AS qty,                                                                                                                                              "
            + "			ROUND( IFNULL( tab18.qty_in, 0 ), 4 ) qty_in,                                                                                                          "
            + "			ROUND( IFNULL( tab18.qty_out, 0 ), 4 ) qty_out,                                                                                                        "
            + "			ROUND( IFNULL( tab18.qty_adjust, 0 ), 4 ) qty_adjust,                                                                                                  "
            + "			ROUND( IFNULL( tab18.qty_diff, 0 ), 4 ) qty_diff,                                                                                                      "
            + "			now() c_time,                                                                                                                                          "
            + "			now() u_time,                                                                                                                                          "
            + "			tab17.label warehouse_type_name,                                                                                                                       "
            + "			0 realtime_amount,                                                                                                                                     "
            + "			0 realtime_price,                                                                                                                                      "
            + "			tab5.warehouse_type warehouse_type,                                                                                                                    "
            + "			tab5.id warehouse_id,                                                                                                                                  "
            + "			tab6.id owner_id                                                                                                                                       "
            + "		FROM                                                                                                                                                       "
            + "			(                                                                                                                                                      "
            + "		SELECT                                                                                                                               					   "
            + "			warehouse_id,                                                                                                                    					   "
            + "			owner_id,                                                                                                                        					   "
            + "			sku_id,                                                                                                                          					   "
            + "			unit_id,                                                                                                                         					   "
            + "			sum( qty_in ) qty_in,                                                                                                            					   "
            + "			sum( qty_out ) qty_out,                                                                                                          					   "
            + "			sum( qty_adjust ) qty_adjust,                                                                                                    					   "
            + "			sum( qty_in ) - sum( qty_out ) + sum( qty_adjust ) AS qty                                                                        					   "
            + "		FROM                                                                                                                                 					   "
            + "			(                                                                                                                                					   "
            + "			SELECT                                                                                                                           					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id,                                                                                                                   					   "
            + "				t1.unit_id,                                                                                                                  					   "
            + "				sum( t1.actual_weight ) qty_in,                                                                                              					   "
            + "				0 qty_out,                                                                                                                   					   "
            + "				0 qty_adjust                                                                                                                 					   "
            + "			FROM                                                                                                                             					   "
            + "				b_in t1                                                                                                                      					   "
            + "			WHERE                                                                                                                            					   "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    					   "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) &lt;= DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         					   "
            + "			GROUP BY                                                                                                                         					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id UNION ALL                                                                                                          					   "
            + "			SELECT                                                                                                                           					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id,                                                                                                                   					   "
            + "				t1.unit_id,                                                                                                                  					   "
            + "				0 qty_in,                                                                                                                    					   "
            + "				sum( t1.actual_weight ) qty_out,                                                                                             					   "
            + "				0 qty_adjust                                                                                                                 					   "
            + "			FROM                                                                                                                             					   "
            + "				b_out t1                                                                                                                     					   "
            + "			WHERE                                                                                                                            					   "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    					   "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) &lt;= DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         					   "
            + "			GROUP BY                                                                                                                         					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id UNION ALL                                                                                                          					   "
            + "			SELECT                                                                                                                           					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t2.owner_id,                                                                                                                 					   "
            + "				t1.sku_id,                                                                                                                   					   "
            + "				NULL unit_id,                                                                                                                					   "
            + "				0 qty_in,                                                                                                                    					   "
            + "				0 qty_out,                                                                                                                   					   "
            + "				sum( t1.qty_diff ) qty_adjust                                                                                                					   "
            + "			FROM                                                                                                                             					   "
            + "				b_adjust_detail t1                                                                                                           					   "
            + "				LEFT JOIN b_adjust t2 ON t2.id = t1.adjust_id                                                                                					   "
            + "			WHERE                                                                                                                            					   "
            + "				t1.STATUS = '2'                                                                                                              					   "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) &lt;= DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         					   "
            + "			GROUP BY                                                                                                                         					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t2.owner_id,                                                                                                                 					   "
            + "				t1.sku_id                                                                                                                    					   "
            + "			) ttab                                                                                                                           					   "
            + "		GROUP BY                                                                                                                             					   "
            + "			warehouse_id,                                                                                                                    					   "
            + "			sku_id,                                                                                                                          					   "
            + "			owner_id                                                                                                                         					   "
            + "			) tab1                                                                                                                                                 "
            + "			LEFT JOIN m_warehouse tab5 ON tab1.warehouse_id = tab5.id                                                                                              "
            + "			LEFT JOIN m_owner tab6 ON tab1.owner_id = tab6.id                                                                                                      "
            + "			LEFT JOIN m_goods_spec tab7 ON tab1.sku_id = tab7.id                                                                                                   "
            + "			LEFT JOIN m_location tab8 ON tab8.warehouse_id = tab5.id                                                                                               "
            + "			LEFT JOIN m_bin tab9 ON tab9.location_id = tab8.id                                                                                                     "
            + "			LEFT JOIN m_inventory tab10 ON tab1.warehouse_id = tab10.warehouse_id                                                                                  "
            + "			AND tab1.owner_id = tab10.owner_id                                                                                                                     "
            + "			AND tab1.sku_id = tab10.sku_id                                                                                                                         "
            + "			LEFT JOIN m_goods tab11 ON tab7.goods_id = tab11.id                                                                                                    "
            + "			LEFT JOIN m_category tab12 ON tab11.category_id = tab12.id                                                                                             "
            + "			LEFT JOIN m_industry tab13 ON tab13.id = tab12.industry_id                                                                                             "
            + "			LEFT JOIN m_business_type tab14 ON tab14.id = tab13.business_id                                                                                        "
            + "			LEFT JOIN m_goods_spec_prop tab15 ON tab15.id = tab7.prop_id                                                                                           "
            + "			LEFT JOIN m_unit tab16 ON tab1.unit_id = tab16.id                                                                                                      "
            + "			LEFT JOIN v_dict_info tab17 ON tab17.CODE = 'm_warehouse_type'                                                                                         "
            + "			AND tab17.dict_value = tab5.warehouse_type                                                                                                             "
            + "			LEFT JOIN (                                                                                                                                            "
            + "		SELECT                                                                                                                               					   "
            + "			warehouse_id,                                                                                                                    					   "
            + "			owner_id,                                                                                                                        					   "
            + "			sku_id,                                                                                                                          					   "
            + "			unit_id,                                                                                                                         					   "
            + "			sum( qty_in ) qty_in,                                                                                                            					   "
            + "			sum( qty_out ) qty_out,                                                                                                          					   "
            + "			sum( qty_adjust ) qty_adjust,                                                                                                    					   "
            + "			sum( qty_in ) - sum( qty_out ) + sum( qty_adjust ) AS qty_diff                                                                        				   "
            + "		FROM                                                                                                                                 					   "
            + "			(                                                                                                                                					   "
            + "			SELECT                                                                                                                           					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id,                                                                                                                   					   "
            + "				t1.unit_id,                                                                                                                  					   "
            + "				sum( t1.actual_weight ) qty_in,                                                                                              					   "
            + "				0 qty_out,                                                                                                                   					   "
            + "				0 qty_adjust                                                                                                                 					   "
            + "			FROM                                                                                                                             					   "
            + "				b_in t1                                                                                                                      					   "
            + "			WHERE                                                                                                                            					   "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    					   "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) = DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         					       "
            + "			GROUP BY                                                                                                                         					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id UNION ALL                                                                                                          					   "
            + "			SELECT                                                                                                                           					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id,                                                                                                                   					   "
            + "				t1.unit_id,                                                                                                                  					   "
            + "				0 qty_in,                                                                                                                    					   "
            + "				sum( t1.actual_weight ) qty_out,                                                                                             					   "
            + "				0 qty_adjust                                                                                                                 					   "
            + "			FROM                                                                                                                             					   "
            + "				b_out t1                                                                                                                     					   "
            + "			WHERE                                                                                                                            					   "
            + "				t1.STATUS IN ( '1', '2' )                                                                                                    					   "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) = DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         					       "
            + "			GROUP BY                                                                                                                         					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t1.owner_id,                                                                                                                 					   "
            + "				t1.sku_id UNION ALL                                                                                                          					   "
            + "			SELECT                                                                                                                           					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t2.owner_id,                                                                                                                 					   "
            + "				t1.sku_id,                                                                                                                   					   "
            + "				NULL unit_id,                                                                                                                					   "
            + "				0 qty_in,                                                                                                                    					   "
            + "				0 qty_out,                                                                                                                   					   "
            + "				sum( t1.qty_diff ) qty_adjust                                                                                                					   "
            + "			FROM                                                                                                                             					   "
            + "				b_adjust_detail t1                                                                                                           					   "
            + "				LEFT JOIN b_adjust t2 ON t2.id = t1.adjust_id                                                                                					   "
            + "			WHERE                                                                                                                            					   "
            + "				t1.STATUS = '2'                                                                                                              					   "
            + "				AND DATE_FORMAT( t1.u_time, '%Y-%m-%d' ) = DATE_SUB( CURDATE(), INTERVAL 0 DAY )                                         				    	   "
            + "			GROUP BY                                                                                                                         					   "
            + "				t1.warehouse_id,                                                                                                             					   "
            + "				t2.owner_id,                                                                                                                 					   "
            + "				t1.sku_id                                                                                                                    					   "
            + "			) ttab                                                                                                                           					   "
            + "		GROUP BY                                                                                                                             					   "
            + "			warehouse_id,                                                                                                                    					   "
            + "			sku_id,                                                                                                                          					   "
            + "			owner_id                                                                                                                         					   "
            + "			) tab18 ON tab1.warehouse_id = tab18.warehouse_id                                                                                                      "
            + "			AND tab1.owner_id = tab18.owner_id                                                                                                                     "
            + "			AND tab1.sku_id = tab18.sku_id                                                                                                                         "
            + "		HAVING                                                                                                                                                     "
            + "			qty != 0 UNION ALL                                                                                                                                     "
            + "		SELECT                                                                                                                                                     "
            + "			t1.sku_id,                                                                                                                                             "
            + "			t1.id,                                                                                                                                                 "
            + "			t1.dt,                                                                                                                                                 "
            + "			t2.CODE owner_code,                                                                                                                                    "
            + "			t2.NAME owner_name,                                                                                                                                    "
            + "			t2.short_name owner_short_name,                                                                                                                        "
            + "			t7.NAME business_type_name,                                                                                                                            "
            + "			t7.CODE business_type_code,                                                                                                                            "
            + "			t6.NAME industry_name,                                                                                                                                 "
            + "			t6.CODE industry_code,                                                                                                                                 "
            + "			t5.NAME category_name,                                                                                                                                 "
            + "			t5.CODE category_code,                                                                                                                                 "
            + "			t4.NAME goods_name,                                                                                                                                    "
            + "			t3.CODE sku_code,                                                                                                                                      "
            + "			t3.spec sku_name,                                                                                                                                      "
            + "			t4.CODE goods_code,                                                                                                                                    "
            + "			t10.id prop_id,                                                                                                                                        "
            + "			t10.CODE prop_code,                                                                                                                                    "
            + "			t10.NAME goods_prop,                                                                                                                                   "
            + "			t3.pm,                                                                                                                                                 "
            + "			t3.CODE spec_code,                                                                                                                                     "
            + "			t3.NAME spec_name,                                                                                                                                     "
            + "			t8.CODE warehouse_code,                                                                                                                                "
            + "			t8.NAME warehouse_name,                                                                                                                                "
            + "			t12.NAME location_name,                                                                                                                                "
            + "			t13.NAME bin_name,                                                                                                                                     "
            + "			t13.id bin_id,                                                                                                                                         "
            + "			'吨' unit_name,                                                                                                                                        "
            + "			t1.qty,                                                                                                                                                "
            + "			t1.qty_in,                                                                                                                                             "
            + "			t1.qty_out,                                                                                                                                            "
            + "			t1.qty_adjust,                                                                                                                                         "
            + "			ifnull( t1.qty_in, 0 )- ifnull( t1.qty_out, 0 )+ ifnull( t1.qty_adjust, 0 ) qty_diff,                                                                  "
            + "			t1.c_time,                                                                                                                                             "
            + "			t1.u_time,                                                                                                                                             "
            + "			t16.label warehouse_type_name,                                                                                                                         "
            + "		CASE                                                                                                                                                       "
            + "				                                                                                                                                                   "
            + "				WHEN t14.sku_id IS NOT NULL THEN                                                                                                                   "
            + "				t1.qty * t1.price ELSE t1.qty * t11.price                                                                                                          "
            + "			END AS realtime_amount,                                                                                                                                "
            + "		CASE                                                                                                                                                       "
            + "				                                                                                                                                                   "
            + "				WHEN t14.sku_id IS NOT NULL THEN                                                                                                                   "
            + "				t1.price ELSE t11.price                                                                                                                            "
            + "			END AS realtime_price,                                                                                                                                 "
            + "			t8.warehouse_type,                                                                                                                                     "
            + "			t8.id warehouse_id,                                                                                                                                    "
            + "			t2.id owner_id                                                                                                                                         "
            + "		FROM                                                                                                                                                       "
            + "			b_daily_inventory t1                                                                                                                                   "
            + "			LEFT JOIN m_owner t2 ON t1.owner_id = t2.id                                                                                                            "
            + "			LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                                                                                         "
            + "			LEFT JOIN m_goods t4 ON t3.goods_id = t4.id                                                                                                            "
            + "			LEFT JOIN m_category t5 ON t4.category_id = t5.id                                                                                                      "
            + "			LEFT JOIN m_industry t6 ON t5.industry_id = t6.id                                                                                                      "
            + "			LEFT JOIN m_business_type t7 ON t6.business_id = t7.id                                                                                                 "
            + "			LEFT JOIN m_warehouse t8 ON t1.warehouse_id = t8.id                                                                                                    "
            + "			LEFT JOIN m_unit t9 ON t1.unit_id = t9.id                                                                                                              "
            + "			LEFT JOIN m_goods_spec_prop t10 ON t3.prop_id = t10.id                                                                                                 "
            + "			LEFT JOIN m_location t12 ON t1.location_id = t12.id                                                                                                    "
            + "			LEFT JOIN m_bin t13 ON t1.bin_id = t13.id                                                                                                              "
            + "			LEFT JOIN (                                                                                                                                            "
            + "			SELECT                                                                                                                                                 "
            + "				sku_id,                                                                                                                                            "
            + "				price,                                                                                                                                             "
            + "				price_dt,                                                                                                                                          "
            + "				c_time,                                                                                                                                            "
            + "				row_number ( ) over ( PARTITION BY sku_id ORDER BY price_dt DESC, c_time DESC ) AS row_num                                                         "
            + "			FROM                                                                                                                                                   "
            + "				b_goods_price                                                                                                                                      "
            + "			) t11 ON t11.sku_id = t1.sku_id                                                                                                                        "
            + "			AND t11.row_num = 1                                                                                                                                    "
            + "			LEFT JOIN (                                                                                                                                            "
            + "			SELECT                                                                                                                                                 "
            + "				t2.target_sku_id sku_id                                                                                                                            "
            + "			FROM                                                                                                                                                   "
            + "				b_material_convert t1                                                                                                                              "
            + "				INNER JOIN b_material_convert_detail t2 ON t2.material_convert_id = t1.id                                                                          "
            + "			WHERE                                                                                                                                                  "
            + "				t1.is_effective = TRUE                                                                                                                             "
            + "				AND t2.is_effective = TRUE                                                                                                                         "
            + "			GROUP BY                                                                                                                                               "
            + "				t2.target_sku_id                                                                                                                                   "
            + "			) t14 ON t14.sku_id = t1.sku_id                                                                                                                        "
            + "			LEFT JOIN v_dict_info t16 ON t16.CODE = 'm_warehouse_type'                                                                                             "
            + "			AND t16.dict_value = t8.warehouse_type                                                                                                                 "
            + "		) tt1                                                                                                                                                      "
            + "		LEFT JOIN (                                                                                                                                                "
            + "		SELECT                                                                                                                                                     "
            + "			sku_id,                                                                                                                                                "
            + "			price,                                                                                                                                                 "
            + "			price_dt,                                                                                                                                              "
            + "			c_time,                                                                                                                                                "
            + "			row_number ( ) over ( PARTITION BY sku_id ORDER BY price_dt DESC, c_time DESC ) AS row_num                                                             "
            + "		FROM                                                                                                                                                       "
            + "			b_goods_price                                                                                                                                          "
            + "		) tt2 ON tt1.sku_id = tt2.sku_id                                                                                                                           "
            + "		AND tt2.row_num = 1                                                                                                                                        "
            + "		LEFT JOIN (                                                                                                                                                "
            + "		SELECT                                                                                                                                                     "
            + "			t2.target_sku_id sku_id                                                                                                                                "
            + "		FROM                                                                                                                                                       "
            + "			b_material_convert t1                                                                                                                                  "
            + "			INNER JOIN b_material_convert_detail t2 ON t2.material_convert_id = t1.id                                                                              "
            + "		WHERE                                                                                                                                                      "
            + "			t1.is_effective = TRUE                                                                                                                                 "
            + "			AND t2.is_effective = TRUE                                                                                                                             "
            + "		GROUP BY                                                                                                                                                   "
            + "		t2.target_sku_id                                                                                                                                           "
            + "		) tt3 ON tt3.sku_id = tt1.sku_id                                                                                                                           "
            + " ,(select @row_num:=0) tt4                                                                                                                                      ";

    /**
     * 页面查询列表
     * @param page
     * @param searchCondition
     * @return
     */
        @Select("  <script>     "
                + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                +common_select
                + "        where true                                                                                                                                        "
//            + "          and (CONCAT(t2.name,t2.short_name) like CONCAT ('%',#{p1.owner_name,jdbcType=VARCHAR},'%') or #{p1.owner_name,jdbcType=VARCHAR} is null)        "
                + "          and (t2.id = #{p1.owner_id} or #{p1.owner_id} is null)                                                                                          "
                + "          and (CONCAT(t3.name,t3.spec,t3.pm,t4.name, '_', t3.code, '_', t4.code) like CONCAT ('%',#{p1.sku_name,jdbcType=VARCHAR},'%') or #{p1.sku_name,jdbcType=VARCHAR} is null)    "
                + "          and (t10.name like CONCAT ('%',#{p1.goods_prop,jdbcType=VARCHAR},'%') or #{p1.goods_prop,jdbcType=VARCHAR} is null or #{p1.goods_prop,jdbcType=VARCHAR} = '') "
                // WMS-617 【优先级A，用户提出1】每日库存表，仓库类型是饲料厂库的仓库，不显示该条数据
                + "          and (t8.warehouse_type != '" + DictConstant.DICT_M_WAREHOUSE_TYPE_CL + "')                                                                      "
                + "         <if test='p1.warehouse_ids != null and p1.warehouse_ids.length!=0' >                                                                             "
                + "          and t1.warehouse_id in                                                                                                                          "
                + "              <foreach collection='p1.warehouse_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
                + "               #{item}                                                                                                                                    "
                + "              </foreach>                                                                                                                                  "
                + "         </if>                                                                                                                                            "
                + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.start_time,jdbcType=DATE} is null)          "
                + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.over_time,jdbcType=DATE} is null)            "

                + "         <if test='p1.owner_ids != null and p1.owner_ids.length!=0' >                                                                             "
                + "          and t1.owner_id in                                                                                                                          "
                + "              <foreach collection='p1.owner_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
                + "               #{item}                                                                                                                                    "
                + "              </foreach>                                                                                                                                  "
                + "         </if>                                                                                                                                            "
                + "          and (t5.name like concat('%', #{p1.category_name}, '%') or #{p1.category_name} is null or #{p1.category_name} is null or #{p1.category_name} = '')                                   "
                + "            <if test='p1.warehouse_types != null and p1.warehouse_types.length!=0' >                                                                                                                                         "
                + "             and t8.warehouse_type in                                                                                                                                                                                        "
                + "                 <foreach collection='p1.warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                                                                                        "
                + "                  #{item}                                                                                                                                                                                                    "
                + "                 </foreach>                                                                                                                                                                                                  "
                + "            </if>                                                                                                                                                                                                            "
                // 仓库权限
                + "     ${p1.params.dataScopeAnnotation}                                                                                                "
                + "   </script>        ")
    IPage<BDailyInventoryVo> selectPage(Page page, @Param("p1") BDailyInventoryVo searchCondition);


    @Select("  <script>                                                                                                                                                                                      "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                                                                                        "
            +common_select_new
            + "        where true                                                                                                                                                                            "
            + "          and (owner_id = #{p1.owner_id} or #{p1.owner_id} is null)                                                                                                                           "
            + "          and (CONCAT(spec_name,sku_name,pm,goods_name, '_', sku_code, '_', goods_code) like CONCAT ('%',#{p1.sku_name,jdbcType=VARCHAR},'%') or #{p1.sku_name,jdbcType=VARCHAR} is null)     "
            + "          and (goods_prop like CONCAT ('%',#{p1.goods_prop,jdbcType=VARCHAR},'%') or #{p1.goods_prop,jdbcType=VARCHAR} is null or #{p1.goods_prop,jdbcType=VARCHAR} = '')                     "
            // WMS-617 【优先级A，用户提出1】每日库存表，仓库类型是饲料厂库的仓库，不显示该条数据
            + "          and (warehouse_type != '" + DictConstant.DICT_M_WAREHOUSE_TYPE_CL + "')                                                                                                             "
            + "         <if test='p1.warehouse_ids != null and p1.warehouse_ids.length!=0' >                                                                                                                 "
            + "          and warehouse_id in                                                                                                                                                                 "
            + "              <foreach collection='p1.warehouse_ids' item='item' index='index' open='(' separator=',' close=')'>                                                                              "
            + "               #{item}                                                                                                                                                                        "
            + "              </foreach>                                                                                                                                                                      "
            + "         </if>                                                                                                                                                                                "
            + "      and (DATE_FORMAT(dt,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.start_time,jdbcType=DATE} is null)                                                 "
            + "      and (DATE_FORMAT(dt,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.over_time,jdbcType=DATE} is null)                                                   "
            + "         <if test='p1.owner_ids != null and p1.owner_ids.length!=0' >                                                                                                                         "
            + "          and owner_id in                                                                                                                                                                     "
            + "              <foreach collection='p1.owner_ids' item='item' index='index' open='(' separator=',' close=')'>                                                                                  "
            + "               #{item}                                                                                                                                                                        "
            + "              </foreach>                                                                                                                                                                      "
            + "         </if>                                                                                                                                                                                "
            + "          and (category_name like concat('%', #{p1.category_name}, '%') or #{p1.category_name} is null or #{p1.category_name} is null or #{p1.category_name} = '')                            "
            + "            <if test='p1.warehouse_types != null and p1.warehouse_types.length!=0' >                                                                                                          "
            + "             and warehouse_type in                                                                                                                                                            "
            + "                 <foreach collection='p1.warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                                                         "
            + "                  #{item}                                                                                                                                                                     "
            + "                 </foreach>                                                                                                                                                                   "
            + "            </if>                                                                                                                                                                             "
            // 仓库权限
        + "     ${p1.params.dataScopeAnnotation}                                                                                                                                                             "
            + "   </script>        ")
    IPage<BDailyInventoryVo> selectPageNew(Page page, @Param("p1") BDailyInventoryVo searchCondition);

    /**
     * 页面查询合计
     * @param searchCondition
     * @return
     */
    @Select("  <script>     "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            +sum_select
            + "        where true                                                                                                                                        "
//            + "          and (CONCAT(t2.name,t2.short_name) like CONCAT ('%',#{p1.owner_name,jdbcType=VARCHAR},'%') or #{p1.owner_name,jdbcType=VARCHAR} is null)        "
            + "          and (t2.id = #{p1.owner_id} or #{p1.owner_id} is null)                                                                                          "
            + "          and (CONCAT(t3.name,t3.spec,t3.pm,t4.name, '_', t3.code, '_', t4.code) like CONCAT ('%',#{p1.sku_name,jdbcType=VARCHAR},'%') or #{p1.sku_name,jdbcType=VARCHAR} is null)    "
            + "          and (t10.name like CONCAT ('%',#{p1.goods_prop,jdbcType=VARCHAR},'%') or #{p1.goods_prop,jdbcType=VARCHAR} is null or #{p1.goods_prop,jdbcType=VARCHAR} = '') "
            // WMS-617 【优先级A，用户提出1】每日库存表，仓库类型是饲料厂库的仓库，不显示该条数据
            + "          and (t8.warehouse_type != '" + DictConstant.DICT_M_WAREHOUSE_TYPE_CL + "')                                                                      "
            + "         <if test='p1.warehouse_ids != null and p1.warehouse_ids.length!=0' >                                                                             "
            + "          and t1.warehouse_id in                                                                                                                          "
            + "              <foreach collection='p1.warehouse_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
            + "               #{item}                                                                                                                                    "
            + "              </foreach>                                                                                                                                  "
            + "         </if>                                                                                                                                            "
            + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.start_time,jdbcType=DATE} is null)          "
            + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.over_time,jdbcType=DATE} is null)            "
            + "         <if test='p1.owner_ids != null and p1.owner_ids.length!=0' >                                                                             "
            + "          and t1.owner_id in                                                                                                                          "
            + "              <foreach collection='p1.owner_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
            + "               #{item}                                                                                                                                    "
            + "              </foreach>                                                                                                                                  "
            + "         </if>                                                                                                                                            "
            + "          and (t5.name like concat('%', #{p1.category_name}, '%') or #{p1.category_name} is null or #{p1.category_name} is null or #{p1.category_name} = '')                                   "
            + "            <if test='p1.warehouse_types != null and p1.warehouse_types.length!=0' >                                                                                                                                         "
            + "             and t8.warehouse_type in                                                                                                                                                                                        "
            + "                 <foreach collection='p1.warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                                                                                        "
            + "                  #{item}                                                                                                                                                                                                    "
            + "                 </foreach>                                                                                                                                                                                                  "
            + "            </if>                                                                                                                                                                                                            "
            // 仓库权限
            + "     ${p1.params.dataScopeAnnotation}                                                                                                "
            + "   </script>        ")
    BDailyInventorySumVo selectSumData(@Param("p1") BDailyInventoryVo searchCondition);

    /**
     * 页面查询合计
     * @param searchCondition
     * @return
     */
    @Select("  <script>     "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                                                                                                                       "
            +sum_select_new
            + "        where true                                                                                                                                                                                                           "
            + "          and (tt1.owner_id = #{p1.owner_id} or #{p1.owner_id} is null)                                                                                                                                                      "
            + "          and (CONCAT(tt1.spec_name,tt1.sku_name,tt1.pm,tt1.goods_name, '_', tt1.sku_code, '_',tt1.goods_code) like CONCAT ('%',#{p1.sku_name,jdbcType=VARCHAR},'%') or #{p1.sku_name,jdbcType=VARCHAR} is null)             "
            + "          and (tt1.goods_prop like CONCAT ('%',#{p1.goods_prop,jdbcType=VARCHAR},'%') or #{p1.goods_prop,jdbcType=VARCHAR} is null or #{p1.goods_prop,jdbcType=VARCHAR} = '')                                                "
            // WMS-617 【优先级A，用户提出1】每日库存表，仓库类型是饲料厂库的仓库，不显示该条数据
            + "          and (tt1.warehouse_type != '" + DictConstant.DICT_M_WAREHOUSE_TYPE_CL + "')                                                                                                                                        "
            + "         <if test='p1.warehouse_ids != null and p1.warehouse_ids.length!=0' >                                                                                                                                                "
            + "          and tt1.warehouse_id in                                                                                                                                                                                            "
            + "              <foreach collection='p1.warehouse_ids' item='item' index='index' open='(' separator=',' close=')'>                                                                                                             "
            + "               #{item}                                                                                                                                                                                                       "
            + "              </foreach>                                                                                                                                                                                                     "
            + "         </if>                                                                                                                                                                                                               "
            + "      and (DATE_FORMAT(tt1.dt,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.start_time,jdbcType=DATE} is null)                                                                            "
            + "      and (DATE_FORMAT(tt1.dt,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.over_time,jdbcType=DATE} is null)                                                                              "
            + "         <if test='p1.owner_ids != null and p1.owner_ids.length!=0' >                                                                                                                                                        "
            + "          and tt1.owner_id in                                                                                                                                                                                                "
            + "              <foreach collection='p1.owner_ids' item='item' index='index' open='(' separator=',' close=')'>                                                                                                                 "
            + "               #{item}                                                                                                                                                                                                       "
            + "              </foreach>                                                                                                                                                                                                     "
            + "         </if>                                                                                                                                                                                                               "
            + "          and (tt1.category_name like concat('%', #{p1.category_name}, '%') or #{p1.category_name} is null or #{p1.category_name} is null or #{p1.category_name} = '')                                                       "
            + "            <if test='p1.warehouse_types != null and p1.warehouse_types.length!=0' >                                                                                                                                         "
            + "             and tt1.warehouse_type in                                                                                                                                                                                       "
            + "                 <foreach collection='p1.warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                                                                                        "
            + "                  #{item}                                                                                                                                                                                                    "
            + "                 </foreach>                                                                                                                                                                                                  "
            + "            </if>                                                                                                                                                                                                            "
            // 仓库权限
            + "     ${p1.params.dataScopeAnnotation}                                                                                                                                                                                        "
            + "   </script>        ")
    BDailyInventorySumVo selectSumDataNew(@Param("p1") BDailyInventoryVo searchCondition);


    /**
     * 页面查询列表
     * @param searchCondition
     * @return
     */
    @Select("   <script>                                                                                                                                                 "
            + common_select
            + "  where true                                                                                                                                              "
            + "   <if test='p1 != null and p1.size!=0' >                                                                                                                 "
            + "     and t1.id in                                                                                                                                         "
            + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>                                                              "
            + "         #{item.id,jdbcType=INTEGER}                                                                                                                      "
            + "        </foreach>                                                                                                                                        "
            + "   </if>                                                                                                                                                  "
            + "  </script>    ")
    List<MDailyInventoryExportVo> selectExportList(@Param("p1") List<BDailyInventoryVo> searchCondition);

    /**
     * 页面查询列表
     * @param searchCondition
     * @return
     */
    @Select("   <script>                                                                                                                                                 "
            + common_select_new
            + "  where true                                                                                                                                              "
            + "   <if test='p1 != null and p1.size!=0' >                                                                                                                 "
            + "     and id in                                                                                                                                         "
            + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>                                                              "
            + "         #{item.id,jdbcType=INTEGER}                                                                                                                      "
            + "        </foreach>                                                                                                                                        "
            + "   </if>                                                                                                                                                  "
            + "  </script>    ")
    List<MDailyInventoryExportVo> selectExportListNew(@Param("p1") List<BDailyInventoryVo> searchCondition);

    /**
     * 页面查询列表
     * @param searchCondition
     * @return List<MDailyInventoryExportVo>
     */
    @Select("  <script>     "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            +common_select
            + "        where true                                                                                                                                        "
//            + "          and (CONCAT(t2.name,t2.short_name) like CONCAT ('%',#{p1.owner_name,jdbcType=VARCHAR},'%') or #{p1.owner_name,jdbcType=VARCHAR} is null)        "
            + "          and (CONCAT(t3.name,t3.spec,t3.pm,t4.name, '_', t3.code, '_', t4.code) like CONCAT ('%',#{p1.sku_name,jdbcType=VARCHAR},'%') or #{p1.sku_name,jdbcType=VARCHAR} is null)    "
            + "          and (t10.name like CONCAT ('%',#{p1.goods_prop,jdbcType=VARCHAR},'%') or #{p1.goods_prop,jdbcType=VARCHAR} is null or #{p1.goods_prop,jdbcType=VARCHAR} = '') "
            + "          and (t2.id = #{p1.owner_id} or #{p1.owner_id} is null)                                                                                          "
            + "          and (t8.warehouse_type != '" + DictConstant.DICT_M_WAREHOUSE_TYPE_CL + "')                                                                      "
            + "         <if test='p1.warehouse_ids != null and p1.warehouse_ids.length!=0' >                                                                             "
            + "          and t1.warehouse_id in                                                                                                                          "
            + "              <foreach collection='p1.warehouse_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
            + "               #{item}                                                                                                                                    "
            + "              </foreach>                                                                                                                                  "
            + "         </if>                                                                                                                                            "
            + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.start_time,jdbcType=DATE} is null)          "
            + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.over_time,jdbcType=DATE} is null)            "
            + "         <if test='p1.owner_ids != null and p1.owner_ids.length!=0' >                                                                             "
            + "          and t1.owner_id in                                                                                                                          "
            + "              <foreach collection='p1.owner_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
            + "               #{item}                                                                                                                                    "
            + "              </foreach>                                                                                                                                  "
            + "         </if>                                                                                                                                            "
            + "          and (t5.name like concat('%', #{p1.category_name}, '%') or #{p1.category_name} is null or #{p1.category_name} is null or #{p1.category_name} = '')                                   "
            + "            <if test='p1.warehouse_types != null and p1.warehouse_types.length!=0' >                                                                                                                                         "
            + "             and t8.warehouse_type in                                                                                                                                                                                        "
            + "                 <foreach collection='p1.warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                                                                                        "
            + "                  #{item}                                                                                                                                                                                                    "
            + "                 </foreach>                                                                                                                                                                                                  "
            + "            </if>                                                                                                                                                                                                            "

            // 仓库权限
            + "     ${p1.params.dataScopeAnnotation}                                                                                                "
            + "   </script>        ")
    List<MDailyInventoryExportVo> selectExportAllList(@Param("p1") BDailyInventoryVo searchCondition);

    /**
     * 页面查询列表
     * @param searchCondition
     * @return List<MDailyInventoryExportVo>
     */
    @Select("  <script>     "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                                                                           "
            +common_select_new
    + "        where true                                                                                                                                                                       "
//            + "          and (CONCAT(t2.name,t2.short_name) like CONCAT ('%',#{p1.owner_name,jdbcType=VARCHAR},'%') or #{p1.owner_name,jdbcType=VARCHAR} is null)                             "
            + "          and (CONCAT(goods_name,sku_name,pm,sku_code, goods_code) like CONCAT ('%',#{p1.sku_name,jdbcType=VARCHAR},'%') or #{p1.sku_name,jdbcType=VARCHAR} is null)             "
            + "          and (goods_prop like CONCAT ('%',#{p1.goods_prop,jdbcType=VARCHAR},'%') or #{p1.goods_prop,jdbcType=VARCHAR} is null or #{p1.goods_prop,jdbcType=VARCHAR} = '')        "
            + "          and (owner_id = #{p1.owner_id} or #{p1.owner_id} is null)                                                                                                              "
            + "          and (warehouse_type != '" + DictConstant.DICT_M_WAREHOUSE_TYPE_CL + "')                                                                                                "
            + "         <if test='p1.warehouse_ids != null and p1.warehouse_ids.length!=0' >                                                                                                    "
            + "          and warehouse_id in                                                                                                                                                    "
            + "              <foreach collection='p1.warehouse_ids' item='item' index='index' open='(' separator=',' close=')'>                                                                 "
            + "               #{item}                                                                                                                                                           "
            + "              </foreach>                                                                                                                                                         "
            + "         </if>                                                                                                                                                                   "
            + "      and (DATE_FORMAT(dt,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.start_time,jdbcType=DATE} is null)                                    "
            + "      and (DATE_FORMAT(dt,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.over_time,jdbcType=DATE} is null)                                      "
            + "         <if test='p1.owner_ids != null and p1.owner_ids.length!=0' >                                                                                                            "
            + "          and owner_id in                                                                                                                                                        "
            + "              <foreach collection='p1.owner_ids' item='item' index='index' open='(' separator=',' close=')'>                                                                     "
            + "               #{item}                                                                                                                                                           "
            + "              </foreach>                                                                                                                                                         "
            + "         </if>                                                                                                                                                                   "
            + "          and (t5.name like concat('%', #{p1.category_name}, '%') or #{p1.category_name} is null or #{p1.category_name} is null or #{p1.category_name} = '')                     "
            + "            <if test='p1.warehouse_types != null and p1.warehouse_types.length!=0' >                                                                                             "
            + "             and warehouse_type in                                                                                                                                               "
            + "                 <foreach collection='p1.warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                                            "
            + "                  #{item}                                                                                                                                                        "
            + "                 </foreach>                                                                                                                                                      "
            + "            </if>                                                                                                                                                                "
            // 仓库权限
            + "     ${p1.params.dataScopeAnnotation}                                                                                                                                            "
            + "   </script>        ")
    List<MDailyInventoryExportVo> selectExportAllListNew(@Param("p1") BDailyInventoryVo searchCondition);

    /**
     * 导出数量
     * @param searchCondition
     * @return
     */
    @Select("  <script>     "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            + "			SELECT                                                                                                                                           "
            + "             count(1)                                                                                                                                     "
            + "			FROM                                                                                                                                             "
            + "				b_daily_inventory t1                                                                                                                         "
            + "				LEFT JOIN m_goods_spec t3 on t1.sku_id = t3.id                                                                                               "
            + "				LEFT JOIN m_goods t4 on t3.goods_id = t4.id                                                                                                  "
            + "				LEFT JOIN m_category t5 on t4.category_id = t5.id                                                                                            "
            + "				LEFT JOIN m_goods_spec_prop t10 on t3.prop_id = t10.id                                                                                       "
            + "				LEFT JOIN m_warehouse t8 on t1.warehouse_id = t8.id                                                                                          "
            + "        where true                                                                                                                                           "
            + "          and (t1.owner_id = #{p1.owner_id} or #{p1.owner_id} is null)                                                                                          "
            + "          and (CONCAT(t3.name,t3.spec,t3.pm,t4.name, '_', t3.code, '_', t4.code) like CONCAT ('%',#{p1.sku_name,jdbcType=VARCHAR},'%') or #{p1.sku_name,jdbcType=VARCHAR} is null)    "
            + "          and (t10.name like CONCAT ('%',#{p1.goods_prop,jdbcType=VARCHAR},'%') or #{p1.goods_prop,jdbcType=VARCHAR} is null or #{p1.goods_prop,jdbcType=VARCHAR} = '') "
            + "          and (t8.warehouse_type != '" + DictConstant.DICT_M_WAREHOUSE_TYPE_CL + "')                                                                      "
            + "         <if test='p1.warehouse_ids != null and p1.warehouse_ids.length!=0' >                                                                             "
            + "          and t1.warehouse_id in                                                                                                                          "
            + "              <foreach collection='p1.warehouse_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
            + "               #{item}                                                                                                                                    "
            + "              </foreach>                                                                                                                                  "
            + "         </if>                                                                                                                                            "
            + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.start_time,jdbcType=DATE} is null)          "
            + "      and (DATE_FORMAT(t1.dt,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE},'%Y-%m-%d') or #{p1.over_time,jdbcType=DATE} is null)            "
            + "         <if test='p1.owner_ids != null and p1.owner_ids.length!=0' >                                                                             "
            + "          and t1.owner_id in                                                                                                                          "
            + "              <foreach collection='p1.owner_ids' item='item' index='index' open='(' separator=',' close=')'>                                          "
            + "               #{item}                                                                                                                                    "
            + "              </foreach>                                                                                                                                  "
            + "         </if>                                                                                                                                            "
            + "          and (t5.name like concat('%', #{p1.category_name}, '%') or #{p1.category_name} is null or #{p1.category_name} is null or #{p1.category_name} = '')                                   "
            + "            <if test='p1.warehouse_types != null and p1.warehouse_types.length!=0' >                                                                                                                                         "
            + "             and t8.warehouse_type in                                                                                                                                                                                        "
            + "                 <foreach collection='p1.warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                                                                                        "
            + "                  #{item}                                                                                                                                                                                                    "
            + "                 </foreach>                                                                                                                                                                                                  "
            + "            </if>                                                                                                                                                                                                            "
            // 仓库权限
            + "     ${p1.params.dataScopeAnnotation}                                                                                                "
            + "   </script>        ")
    int selectExportNum(@Param("p1") BDailyInventoryVo searchCondition);
}
